#include "playdelegate.h"
#include "play.h"
#include "heart.h"
#include "add.h"

void PlayDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
                    const QModelIndex &index) const
{
    if (index.data().canConvert<Play>()) {
        Play play = qvariant_cast<Play>(index.data());
        play.paint(painter, option.rect);
    } else if(index.data().canConvert<Heart>()) {
        Heart heart = qvariant_cast<Heart>(index.data());
        heart.paint(painter, option.rect);
    } else if (index.data().canConvert<Add>()) {
        Add add = qvariant_cast<Add>(index.data());
        add.paint(painter, option.rect);
    } else {
        QStyledItemDelegate::paint(painter, option, index);
    }
}

QSize PlayDelegate::sizeHint(const QStyleOptionViewItem &option,
                        const QModelIndex &index) const
{
    if (index.data().canConvert<Play>()) {
        Play play = qvariant_cast<Play>(index.data());
        return play.sizeHint();
    } else if (index.data().canConvert<Heart>()) {
        Heart heart = qvariant_cast<Heart>(index.data());
        return heart.sizeHint();
    } else if (index.data().canConvert<Add>()) {
        Add add = qvariant_cast<Add>(index.data());
        return add.sizeHint();
    } else {
        return QStyledItemDelegate::sizeHint(option, index);
    }
}
